#!/usr/bin/env python
import pygame
import sys
from random import *
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
import gl

rot = 0
tex = None
font = None
string = '''Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor. Aenean massa.
    Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.
Nulla consequat massa quis enim.'''

def init(w, h):
    pygame.display.set_mode((w, h), DOUBLEBUF | OPENGL)
    pygame.display.set_caption('PyOpengl example 1')
    
    print pygame.display.Info()
    
    gl.glInit(w, h)

def draw():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glEnable(GL_TEXTURE_2D)
    #tex.draw((300, 200), rotation = rot)
    font.render(str(c.get_fps()), (0, 400 - font.line_heigth))
    font.render(string, (25, 350))#, rotation = rot, tint=(1, 0, 0, 1))
    font.render(str(font.length(string)), (10, 10 + font.line_heigth))
    font.render(str(len(string)), (10, 10))
    
    pygame.display.flip()
    
def loadImage(name):
    img = pygame.image.load(name)
    
    return gl.GLSurface(img)

if __name__ == '__main__':
    init(600, 400)
    c = pygame.time.Clock()
    tex = loadImage('data/img/cylon.png')
    font = gl.GLFont()
    print 'image loaded'
    while(1):
        c.tick(60)
        rot += 1
        rot %= 360
        for event in pygame.event.get():
            if event.type == QUIT or event.type == KEYUP and event.key == K_ESCAPE:
                sys.exit(0)
            elif event.type == KEYUP and event.key == K_f:
                print c.get_fps()
        
        draw()
